<template>
  <div>
    <h1>登陆页面</h1>
    <hr>
    账号：<input type="text" v-model="account" > <br/>
    密码：<input type="text" v-model="password" > <br />
    <a-button @click="handleloginRouter" type="primary">登陆</a-button>
  </div>
</template>
<script lang="ts">
import { Button } from 'ant-design-vue'
import { defineComponent, reactive, ref } from 'vue'
import { useRouter } from 'vue-router'
import { useStore } from 'vuex'
import axios from 'axios'
export default defineComponent({

  setup(props, context){
    const account = ref('')
    const password = ref('')
    const router = useRouter();
    const store = useStore();
    const handleloginRouter = async () => {

      const result = await store.dispatch('GetLogin',
      { userName: account.value, pwd: password.value })
      console.log("result登陆结果", result)
      if (result.code === 0) {
        router.push('/layouts/home')
      }


      // router.push('/layouts/home')

      //   console.log('account:', account.value)
      //   console.log('password:', password.value)
      //  const result  = await store.dispatch('update_token', {
      //    account: account.value,
      //    password: password.value
      //  })
      //  if (result.msg === 'success') {
      //   router.push('/layouts/home')
      //  }
      //  console.log('result:', result)

      // router.push('/layouts/home')
      // const data = await axios.get('/api/login', {
      //   params: {
      //     userName: account.value,
      //     pwd: password.value
      //   }
      // })
      // const info = data.data
      // console.log(info, 'data')
      // if (info.code !== -1) {
      //   localStorage.setItem('userInfo', JSON.stringify(info.data))

      //  setTimeout(() => {
      //   router.push('/layouts/home')
      //  }, 2000);
      // } else {
      //  alert('用户信息输入有误')
      // }
    }

    return {
      handleloginRouter,
      account,
      password
    }
  }
})
</script>
